home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / RAND / BM132A.LZH / bm_132a / render.s < prev    next >
Encoding:
Text File  |  1995-11-15  |  8.1 KB  |  332 lines

  1. *=======================================================*
  2. *    Rendering module: latest update 12/11/95    *
  3. *=======================================================*
  4. *    Render walls & floors onto screenbuffer        *
  5. *=======================================================*
  6. *     >    New 68030 module by Douglas Little.        *
  7. *=======================================================*
  8. *    Some improvements made to original process:    *
  9. *=======================================================*
  10. *     >    Simplified program-flow, lower overheads    *
  11. *     >    Transparency handled in the form of glass.    *
  12. *     >    Wall runs now stored in a 'frame' chunk.    *
  13. *          Will be changed to work with 'sector' chunks.    *
  14. *     >    Would benefit from instruction-towers, but    *
  15. *          should be avoided until tex-mapping is ready.    *
  16. *=======================================================*
  17.  
  18. towered_walls        ; use instruction-tower for walls
  19. towered_flats        ; use instruction-tower for floors
  20.  
  21. *-------------------------------------------------------*
  22. *    Pigment coefficients for glass windows        *
  23. *-------------------------------------------------------*
  24.  
  25. glass_red        =    3    ; glass diffuse colour.
  26. glass_green        =    5
  27. glass_blue        =    7
  28.  
  29. glass_redfilter        =    8    ; glass filter colour.
  30. glass_greenfilter    =    16
  31. glass_bluefilter    =    32
  32.  
  33. *-------------------------------------------------------*
  34.     ifnd        towered_flats
  35. *-------------------------------------------------------*
  36.     
  37. *-------------------------------------------------------*
  38. *    Render the floors & ceilings            *
  39. *-------------------------------------------------------*
  40. render_flats:
  41. *-------------------------------------------------------*
  42.     lea        flatruns,a0
  43.     lea        flatruncounts,a1
  44.     moveq        #0,d5
  45.     move.w        ScrWidth,d5
  46.     add.l        d5,d5
  47.     move.l        d5,a5
  48.     move.w        Width,d5
  49.     move.l        screen,a2
  50.     move.w        Height,d7
  51.     subq.w        #1,d7
  52. .flats:    move.l        a0,a3
  53.     move.w        (a1)+,d6
  54.     subq.w        #1,d6
  55.     bmi.s        .flat
  56. .runs:    move.w        flat_x2(a3),d2
  57.     move.w        flat_x1(a3),d1
  58.     sub.w        d1,d2
  59.     ble.s        .run
  60.     move.w        flat_id(a3),d3
  61.     lea        (a2,d1.w*2),a4
  62.     subq.w        #1,d2
  63. .dots:    move.w        d3,(a4)+
  64.     dbra        d2,.dots
  65. .run:    addq.l        #flat_len,a3
  66.     dbra        d6,.runs
  67. .flat:    lea        (flat_len*max_xint)(a0),a0
  68.     add.l        a5,a2
  69.     dbra        d7,.flats
  70.     rts
  71.  
  72. *-------------------------------------------------------*
  73.     elseif
  74. *-------------------------------------------------------*
  75.  
  76. *-------------------------------------------------------*
  77. *    Render the floors & ceilings            *
  78. *-------------------------------------------------------*
  79. render_flats:
  80. *-------------------------------------------------------*
  81.     lea        flatruns,a0
  82.     lea        flatruncounts,a1
  83.     moveq        #0,d5
  84.     move.w        scrwidth,d5
  85.     add.l        d5,d5
  86.     move.l        d5,a5
  87.     move.w        width,d5
  88.     move.l        screen,a2
  89.     move.w        height,d7
  90.     subq.w        #1,d7
  91. .flats:    move.l        a0,a3
  92.     move.w        (a1)+,d6
  93.     subq.w        #1,d6
  94.     bmi.s        .flat
  95. .runs:    move.w        flat_id(a3),d3
  96.     move.w        flat_x2(a3),d2
  97.     move.w        d3,d1
  98.     swap        d3
  99.     move.w        d1,d3
  100.     move.w        flat_x1(a3),d1
  101.     sub.w        d1,d2
  102.     ble.s        .run
  103.     lea        (a2,d1.w*2),a4
  104.     moveq        #4-1,d1
  105.     and.w        d2,d1
  106.     lsr.w        #2,d2
  107.     neg.w        d1
  108.     jmp        .tower(pc,d1.w*2)
  109.     move.w        d3,(a4)+
  110.     move.w        d3,(a4)+
  111.     move.w        d3,(a4)+
  112.     move.w        d3,(a4)+
  113. .tower:    dbra        d2,.dots
  114.     addq.l        #flat_len,a3
  115.     dbra        d6,.runs
  116.     bra.s        .flat
  117. .dots:    move.l        d3,(a4)+
  118.     move.l        d3,(a4)+
  119.     dbra        d2,.dots
  120. .run:    addq.l        #flat_len,a3
  121.     dbra        d6,.runs
  122. .flat:    lea        (flat_len*max_xint)(a0),a0
  123.     add.l        a5,a2
  124.     dbra        d7,.flats
  125.     rts
  126.  
  127. *-------------------------------------------------------*
  128.     endc
  129. *-------------------------------------------------------*
  130.  
  131. *-------------------------------------------------------*
  132.     ifnd        towered_walls
  133. *-------------------------------------------------------*
  134.  
  135. *-------------------------------------------------------*
  136. *    Render the walls                *
  137. *-------------------------------------------------------*
  138. render_walls:
  139. *-------------------------------------------------------*
  140.     lea        wallruns,a1
  141.     moveq        #0,d6
  142.     move.w        wallruncount,d6
  143.     moveq        #0,d3
  144.     subq.w        #1,d6
  145.     bmi        .err
  146.     lea        glass,a6
  147.     move.l        d6,d0
  148.     lsl.l        #3,d0
  149.     add.l        d0,a1
  150.     move.l        screen,a4
  151.     moveq        #0,d4
  152.     moveq        #0,d5
  153.     move.w        ScrWidth,d5
  154.     add.l        d5,d5
  155. .runs:    move.w        wall_y2(a1),d2
  156.     moveq        #0,d1
  157.     move.w        wall_y1(a1),d1
  158.     sub.w        d1,d2
  159.     ble.s        .zero
  160.     move.w        wall_x(a1),d0
  161.     bmi.s        .transparent_column
  162.     subq        #1,d2
  163.     move.w        wall_id(a1),d3
  164.     lsl.l        #4,d1
  165.     lea        (a4,d0.w*2),a0
  166.     move.l        d1,d0
  167.     lsl.l        #2,d1
  168.     add.l        d1,d0
  169.     lsl.l        #3,d0
  170.     add.l        d0,a0
  171. .dots:    move.w        d3,(a0)
  172.     add.l        d5,a0
  173.     dbra        d2,.dots
  174. .zero:    subq.l        #wall_len,a1
  175.     dbra        d6,.runs
  176.     bra.s        .err
  177. *-------------------------------------------------------*
  178. *    Transparent walls are treated separately    *
  179. *-------------------------------------------------------*
  180. .transparent_column:
  181. *-------------------------------------------------------*
  182.     not.w        d0
  183.     subq        #1,d2
  184.     move.w        wall_id(a1),d3
  185.     lsl.l        #4,d1
  186.     lea        (a4,d0.w*2),a0
  187.     move.l        d1,d0
  188.     lsl.l        #2,d1
  189.     add.l        d1,d0
  190.     lsl.l        #3,d0
  191.     add.l        d0,a0
  192.     move.w        (a0),d3
  193. .dots2:    move.w        (a6,d3.l*2),(a0)
  194.     add.l        d5,a0
  195.     move.w        (a0),d3
  196.     dbra        d2,.dots2
  197.     subq.l        #wall_len,a1
  198.     dbra        d6,.runs
  199. *-------------------------------------------------------*
  200. .err:    rts
  201.  
  202. *-------------------------------------------------------*
  203.     elseif
  204. *-------------------------------------------------------*
  205.     
  206. *-------------------------------------------------------*
  207. *    Render the walls                *
  208. *-------------------------------------------------------*
  209. render_walls:
  210. *-------------------------------------------------------*
  211.     lea        wallruns,a1
  212.     moveq        #0,d6
  213.     move.w        wallruncount,d6
  214.     moveq        #0,d3
  215.     subq.w        #1,d6
  216.     bmi        .err
  217.     lea        glass,a6
  218.     move.l        d6,d0
  219.     lsl.l        #3,d0
  220.     add.l        d0,a1
  221.     move.l        screen,a4
  222.     moveq        #0,d4
  223.     moveq        #0,d5
  224.     move.w        scrwidth,d5
  225.     add.l        d5,d5
  226. .runs:    move.w        wall_y2(a1),d2
  227.     moveq        #0,d1
  228.     move.w        wall_y1(a1),d1
  229.     sub.w        d1,d2
  230.     ble.s        .zero
  231.     move.w        wall_x(a1),d0
  232.     bmi.s        .transparent_column
  233. ;    subq        #1,d2
  234.     move.w        wall_id(a1),d3
  235.     lsl.l        #4,d1
  236.     lea        (a4,d0.w*2),a0
  237.     move.l        d1,d0
  238.     lsl.l        #2,d1
  239.     add.l        d1,d0
  240.     lsl.l        #3,d0
  241.     add.l        d0,a0
  242.     moveq        #4-1,d1
  243.     and.w        d2,d1
  244.     lsr.w        #2,d2
  245.     neg.w        d1
  246.     jmp        .tower(pc,d1.w*4)
  247. .dots:    move.w        d3,(a0)
  248.     add.l        d5,a0
  249.     rept        4-1
  250.     move.w        d3,(a0)
  251.     add.l        d5,a0
  252.     endr
  253. .tower:    dbra        d2,.dots
  254. .zero:    subq.l        #wall_len,a1
  255.     dbra        d6,.runs
  256.     bra.s        .err
  257. *-------------------------------------------------------*
  258. *    Transparent walls are treated separately    *
  259. *-------------------------------------------------------*
  260. .transparent_column:
  261. *-------------------------------------------------------*
  262.     not.w        d0
  263.     subq        #1,d2
  264.     move.w        wall_id(a1),d3
  265.     lsl.l        #4,d1
  266.     lea        (a4,d0.w*2),a0
  267.     move.l        d1,d0
  268.     lsl.l        #2,d1
  269.     add.l        d1,d0
  270.     lsl.l        #3,d0
  271.     add.l        d0,a0
  272.     move.w        (a0),d3
  273. .dots2:    move.w        (a6,d3.l*2),(a0)
  274.     add.l        d5,a0
  275.     move.w        (a0),d3
  276.     dbra        d2,.dots2
  277.     subq.l        #wall_len,a1
  278.     dbra        d6,.runs
  279. *-------------------------------------------------------*
  280. .err:    rts
  281.  
  282. *-------------------------------------------------------*
  283.     endc
  284. *-------------------------------------------------------*
  285.  
  286. *-------------------------------------------------------*
  287. *    Create transparent translation table        *
  288. *-------------------------------------------------------*
  289. init_glass:
  290. *-------------------------------------------------------*
  291.     lea        glass,a0
  292.     move.l        #65536-1,d0
  293. .make:    move.l        d0,d1
  294.     move.l        d0,d2
  295.     move.l        d0,d3
  296.     lsr.w        #6,d1
  297.     lsr.w        #5,d1
  298.     lsr.w        #5,d2
  299.     and.w        #%11111,d1
  300.     and.w        #%111111,d2
  301.     and.w        #%11111,d3
  302.     mulu        #glass_redfilter,d1
  303.     mulu        #glass_greenfilter,d2
  304.     mulu        #glass_bluefilter,d3
  305.     lsr.w        #5,d1
  306.     lsr.w        #5,d2
  307.     lsr.w        #5,d3
  308.     add.w        #glass_red,d1    
  309.     add.w        #glass_green,d2
  310.     add.w        #glass_blue,d3
  311.     lsr.w        #1,d1    
  312.     lsr.w        #1,d2    
  313.     lsr.w        #1,d3    
  314.     lsl.w        #5,d2
  315.     or.w        d2,d3
  316.     lsl.w        #5,d1
  317.     lsl.w        #6,d1
  318.     or.w        d1,d3
  319.     move.w        d3,(a0,d0.l*2)
  320.     dbra        d0,.make
  321.     rts
  322.  
  323. *-------------------------------------------------------*
  324.             bss
  325. *-------------------------------------------------------*
  326.             
  327. glass:            ds.w    65536
  328.  
  329. *-------------------------------------------------------*
  330.             text
  331. *-------------------------------------------------------*
  332.